<?php

/*
 * File Information Plugin Manager
 * управляет классами возвращающими расширенную информацию о файле
*/

class FIPluginInfo
{
    public $pluginame;
    public $pattern;
    public $classname;
    
    public function __construct($pluginame, $pattern, $classname)
    {
        $this->pluginame = $pluginame;
        $this->pattern = $pattern;
        $this->classname = $classname;
        //echo $pluginame,"  registered ('",$pattern,"', ",$classname,")";
    }
};

class FIPManager
{
    static private $inited = false;
    static private $plugins = array();

    static public function Init()
    {
        if(false !== ($pluginslist = Files::GetRawFileList("core/fileinfoplugins","/^class\.fip\_[a-z0-9_]+\.php$/i")))
        {
            foreach($pluginslist as $p)
                require $p;
            FIPManager::$inited = true;
        } else
            throw new Exception('FileInfoPlugins directory not found.');

    }

    static public function RegisterPlugin($pluginame, $pattern, $classname = null)
    {
        FIPManager::$plugins[] = new FIPluginInfo($pluginame, $pattern, ($classname ? $classname : "fip_".$pluginame));
    }

    static public function GetInfoPlugin($extension)
    {
        if(!FIPManager::$inited)
            FIPManager::Init();

        foreach(FIPManager::$plugins as $plugin)
        {
            if(preg_match($plugin->pattern, strtolower($extension)))
            {
                return new $plugin->classname();
                break;
            }
        }
 
        return null;
    }

};


?>
